/**
 * Created by AllanXu on 7/25/2016.
 */
define(function (require) {
	var Vue = require('vue'),
        Config = require('config'),
		_ = require('ajax'),
		utilities = require('utilities'),
        userId = sessionStorage.id;

    var addCode = sessionStorage.getItem("addCode")?sessionStorage.getItem("addCode"):"33";
	var app = new Vue({
		el: '#activity_list',
		data: {
			// pageIndex: 1,
			pageCount: '',
			pageno: 1,
            renderObj: {
                listArr: []
            },
            tabsName: [],
            typeId: '',
            curNum: -1,
            bottomTxt: '',
			picServer: Config.picServer,
            defaultAdd: '江西省'
		},
		methods:{
			init: function () {
                // 用户信息存session
                utilities.refreshUserInfo(function (data) {
                    // app.renderObj = data;
                    console.log(data);
                });
				// var param = {
				// 	'bind.theme.id': app.typeId,
                 //    'pagesize': 1,
                 //    'pageno': app.pageno
				// };
                var addName = sessionStorage.getItem('addName');
                app.defaultAdd = addName||app.defaultAdd;
				_(Config.SERVICE.ACTIVITY.LIST+'?id='+userId+'&blind.theme.id='+app.typeId+'&pageno='+app.pageno+'&pagesize=10'+'&code='+addCode, {}, function(data) {
				// _(Config.SERVICE.ACTIVITY.LIST+'?id='+4+'&param='+utilities.jsonObjToBase64(param), {}, function(data) {
                    if(app.pageno == 1){
                        app.renderObj.listArr = data.pageitems;
                        app.pageCount = data.pagecount;
                    }else{
                        app.renderObj.listArr = app.renderObj.listArr.concat(data.pageitems);
                    }
                });
			},
			selectAll: function(){
                app.typeId = '';
                app.pageno = 1;
                app.curNum=-1;
                app.init();
			},
			switchTab: function(tabId,index){
				console.log(tabId,index,2);
				app.typeId = tabId;
                app.pageno = 1;
                app.curNum=index;
                app.init();
			},
            goDetail: function (id) {
                location.href = 'activity_detail.html?typeId='+id;
            }
		},
		ready: function() {
			_(Config.DICTIONARY +'?parentId='+952, {}, function(data) {
            	console.log(data);
            	app.tabsName = data.obj['952'];
            	// app.$log();
            });
		}
	});
	app.init();

	window.onscroll = function(){
        var scrolltop = document.body.scrollTop | document.documentElement.scrollTop;
        var clientHeight = document.documentElement.clientHeight;
        if(scrolltop + clientHeight  == document.body.clientHeight){
            if (app.pageno <= app.pageCount){
                app.pageno++;
                app.init();
            }else{
                app.bottomTxt = '到底儿了~';
            }
        }
    }
});